<?php

/*
 * Manager of travel group pages
 * User table : travel_group_tours
 * @author: Tham
 * Date : 3.10.2014
 */

class TravelGroup {

    const TABLENAME = 'travel_group_tours';

    /*
     * Admin paged
     */

    /*
     * List of travel group
     * @author:Tham
     * @param: $limt int[]
     * @param :$start int[]
     * @return $listTravelGroup array[]
     */

    public static function listTravel($start, $limt) {


        global $wpdb;

        $sql_query = 'SELECT * FROM ' . self::TABLENAME . ' '
                . 'LIMIT ' . $start . ' , ' . $limt;

        $listTravelGroup = $wpdb->get_results($sql_query);

        return $listTravelGroup;
    }

    /*
     * count all of travel group
     * @author:Tham
     * @return $listTravelGroup array[]
     */

    public static function countListTravel() {


        global $wpdb;

        $sql_query = 'SELECT count(id_travel_group_tour) as  totaltravel  FROM ' . self::TABLENAME;

        $listTravelGroup = $wpdb->get_results($sql_query);

        return $listTravelGroup;
    }

    /*
     * Insert Data Base on travel group add
     * @author:tham
     * $param :$groupName,$MemberGroup,$startLocation,$endLocation	,$adult	,$children,$class
     * @return none
     */

    public static function insertGroupTravel($groupName, $MemberGroup, $startLocation, $endLocation, $adult, $children, $class) {
        global $wpdb;

        $sql_insert = 'INSERT INTO ' . self::TABLENAME . ' ( group_name,member_group,start_location,end_location,adult,children,class)'
                . '  VALUES ("' . $groupName . '","' . $MemberGroup . '","' . $startLocation . '","' . $endLocation . '",' . $adult . ',' . $children . ',' . $class . ')';
        //echo $sql_insert;
        $wpdb->query($sql_insert);
    }

    /*
     * select travel group by idTravelGroupTour
     * @author:Tham
     * @param idTravelGroupTour;
     * @return $listTravelGroup array[]
     */

    public static function listTravelByIdTravelGroupTour($idTravelGroupTour) {


        global $wpdb;

        $sql_query = 'SELECT  *  '
                . ' FROM ' . self::TABLENAME . " "
                . " WHERE  id_travel_group_tour = " . $idTravelGroupTour;

        $listTravelGroup = $wpdb->get_results($sql_query);

        return $listTravelGroup;
    }

    /*
     * Insert Data Base on travel group add
     * @author:tham
     * $param :$groupName,$MemberGroup,$startLocation,$endLocation	,$adult	,$children,$class
     * @return none
     */

    public static function updateGroupTravel($idTravelGroupTour,$groupName, $MemberGroup, $startLocation, $endLocation, $adult, $children, $class) {
        global $wpdb;

        $sql_update = '    UPDATE ' . self::TABLENAME . '  '
                    . '    SET    group_name = "' . $groupName . '",'
                    . '           member_group = "' . $MemberGroup . '",'
                    . '           start_location  = "' . $startLocation . '" ,'
                    . '           end_location = "' . $endLocation . '",'
                    . '           adult = ' . $adult . ','
                    . '           children = ' . $children . ','
                    . '           class = ' . $class . ''
                    . '    WHERE  id_travel_group_tour = '.$idTravelGroupTour;
        //echo $sql_update;
        $wpdb->query($sql_update);
    }

}
